package com.zycfc.zsf.boot.web.autoconfigure;

import org.springframework.context.annotation.*;
import org.springframework.boot.context.properties.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.*;
import org.springframework.web.bind.support.*;
import org.springframework.core.convert.support.*;
import com.zycfc.zsf.boot.web.converter.*;
import org.springframework.core.convert.converter.*;
import javax.annotation.*;
import org.slf4j.*;

@Configuration
@EnableConfigurationProperties({ WebProperties.class })
public class ConversionServiceAutoConfiguration
{
    private static final Logger log;
    @Autowired
    private ConverterRegistry converterRegistry;
    @Autowired
    private WebProperties properties;
    @Autowired
    private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
    
    @PostConstruct
    public void init() {
        final ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer)this.requestMappingHandlerAdapter.getWebBindingInitializer();
        if (initializer.getConversionService() != null) {
            final GenericConversionService genericConversionService = (GenericConversionService)initializer.getConversionService();
            genericConversionService.addConverter((Converter)new StringToDateConverter());
        }
        if (this.properties.getConverter().getStringToDate().isEnabled()) {
            this.converterRegistry.addConverter((Converter)new StringToDateConverter());
        }
        if (this.properties.getConverter().getStringToBaseEnum().isEnabled()) {
            this.converterRegistry.addConverterFactory((ConverterFactory)new StringToBaseEnumConverterFactory());
        }
        ConversionServiceAutoConfiguration.log.info("^_^Web\u7ec4\u4ef6\u52a0\u8f7d\u6210\u529f^_^");
    }
    
    static {
        log = LoggerFactory.getLogger((Class)ConversionServiceAutoConfiguration.class);
    }
}
